
package com.dyzx.hbb.common.utils;

import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;

import javax.crypto.SecretKey;
import java.util.Base64;

/**
 * JWT密钥生成工具
 */
public class GenerateJwtSecretKey {
    public static void main(String[] args) {
        // 生成一个适合HS256算法的密钥
        SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);


        // 将密钥转换为Base64编码的字符串
        String secretString = Base64.getEncoder().encodeToString(key.getEncoded());


        System.out.println("Generated JWT secret key (Base64 encoded):");
        System.out.println(secretString);
        System.out.println("\nAdd this to your application.yml as:");
        System.out.println("jwt:");
        System.out.println("  secret: " + secretString);
        System.out.println("\nOr to your application.properties as:");
        System.out.println("jwt.secret=" + secretString);
    }
}